<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/8
 * Time: 11:05
 */

namespace app\home\controller;


use app\common\controller\HomeBase;
use think\Db;
use think\Request;

class Info extends HomeBase
{
    public function index()
    {
        $id                = Request::instance()->param('id');
        //栏目信息
        $category          = Db::name('category')
            ->field('id, title, thumb, seo_title, seo_keywords, seo_desc, article_tpl')
            ->where('id', $id)
            ->find();
        if (empty($category))
        {
            return $this->fetch('/public/404');
        }
        //单页信息
        $info              = Db::name('pages')
            ->field('id, title, other_name, category_id, thumb, other_title, keywords, description, author, source, hits, content, photos, enclosure, tpl, create_time')
            ->where('category_id', $id)
            ->find();
        $info['photos']    = json_decode($info['photos'], true);
        $info['enclosure'] = json_decode($info['enclosure'], true);
        $title             = $this->title;
        $description       = $this->description;
        $keywords          = $this->keywords;
        //标题
        if (empty($info['title']))
        {
            if (!empty($category['seo_title']))
            {
                $title = $category['seo_title'];
            }
        } else {
            $title = $info['title'].' - '.$title;
        }
        //关键字
        if (empty($info['keywords']))
        {
            if (!empty($category['seo_keywords']))
            {
                $keywords = $category['seo_keywords'];
            }
        } else {
            $keywords = $info['keywords'];
        }
        //描述
        if (empty($info['description']))
        {
            if (!empty($category['seo_desc']))
            {
                $description = $category['seo_desc'];
            }
        } else {
            $description = $info['description'];
        }
        //模版文件
        $tpl = $category['article_tpl'];
        return view("/$tpl", [
            'category'    => $category,
            'article'     => $info,
            'title'       => $title,
            'keywords'    => $keywords,
            'description' => $description,
        ]);
    }

    //空操作
    public function _empty($name)
    {
        return view('/public/404');
    }
}